<?php
// 玩法控制器
class Controller_WWW_Line extends Controller_WWW_Template
{
    public function __construct ($req, $res)
    {
        $this->template = "smarty:www/line";
        parent::__construct($req, $res);
    }
    public function action_index ($lineType=0)
    {
    	$line = new App_Line();
        $list = $line->getLineTypeList();
        $this->template->set('lineTypeList',$list);
        $this->template->set('lineType',$lineType);
        $cityList=App_City::getCityListCn();
        $this->template->set('cityList',$cityList);
        $this->template->set('step','line');
    }
    public function action_search ()
    {
    	$query = $this->request->query();
    	$page = Arr::get($query,'page');
    	$type= Arr::get($query,'type');
        $city = Arr::get($query,'city');
    	$start = Arr::get($query,'start');
    	$end = Arr::get($query,'end');
    	$chuxing= Arr::get($query,'chuxing');
        $TouristCounts = Arr::get($query,'number');
    	//$fabu = Arr::get($query,'fabu');
    	$age = Arr::get($query,'age');
    	$gender = Arr::get($query,'gender');
    	$identity = Arr::get($query,'identity');
    	$language = Arr::get($query,'language');
    	$price = Arr::get($query,'price');
    	$orders = Arr::get($query,'orders');
    	$score = Arr::get($query,'score');
    	//$scountry = Arr::get($query,'country');
   
    	$page     = max(1, $page);
    	$limit = 6;
    	$offset   = $limit * ($page - 1);
    
    	list($counts,$lines) = App_Line::track_act_search($type,$city,$start,$end,$chuxing,$TouristCounts,
    			$age,$gender,$identity,$language,$price,$orders,$score,$limit,$offset
    	);
        $lines=App_Line::getRebuildData($lines); 
        $pagination = $this->pagination($counts,$limit, $page_type = 'lineajax', $page_key = '',$views = 'www/page/new',$current_page=$page);

    	$html=View::factory('smarty:www/line/content')
              ->set('lines',$lines)
              ->set('pagination',$pagination)
              ->set('counts',$counts)->render();
	
        $ret=array('status'=>1,'content'=>$html);
    	echo json_encode($ret);
        exit;
    }
    public function action_homepage_search ()
    {
        $post=$this->request->post();
        $cityId = Arr::get($post,'city');
        $city=App_City::getNameCnById($cityId, 'cityName');
        $start = Arr::get($post,'start');
        $end = Arr::get($post,'end');
        $TouristCounts = Arr::get($post,'number');
        //传递首页的搜素参数，后由AJAX进行搜索
        $this->template->set('scityId',$cityId);
        $this->template->set('scity',$city);
        $this->template->set('sstart',$start);
        $this->template->set('sstop',$end);
        $this->template->set('snum',$TouristCounts);

        $line = new App_Line();
        //玩法类型列表
        $list = $line->getLineTypeList();
        $this->template->set('lineTypeList',$list);
        //城市列表
        $cityList=App_City::getCityListCn();
        $this->template->set('cityList',$cityList);
        $this->template->set('step','line');

    }

}
